package com.dameng.jianyouquan.interviewer.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.dameng.jianyouquan.R;
import com.dameng.jianyouquan.interviewer.framgent.ChatInterviewerFragment;
import com.dameng.jianyouquan.interviewer.framgent.HomeInterviewerFragment;
import com.dameng.jianyouquan.interviewer.framgent.MyInterviewerFramgent;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class MainInterViewerActivity extends AppCompatActivity {


    @BindView(R.id.vp)
    ViewPager vp;
    @BindView(R.id.rl_homePage)
    RelativeLayout rlHomePage;
    @BindView(R.id.rl_chat)
    RelativeLayout rlChat;
    @BindView(R.id.rl_post)
    RelativeLayout rlPost;
    @BindView(R.id.rl_me)
    RelativeLayout rlMe;
    @BindView(R.id.civ_publish)
    CircleImageView civPublish;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_interviewer);
        ButterKnife.bind(this);

        vp.setAdapter(new MyAdapter(getSupportFragmentManager()));


    }

    @OnClick({R.id.rl_homePage, R.id.rl_chat, R.id.rl_post, R.id.rl_me,R.id.civ_publish})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_homePage:
                vp.setCurrentItem(0);
                break;
            case R.id.rl_chat:
                vp.setCurrentItem(1);
                break;
            case R.id.rl_post:
                vp.setCurrentItem(2);
                break;
            case R.id.rl_me:
                vp.setCurrentItem(3);
                break;
            case R.id.civ_publish:
                startActivity(new Intent(MainInterViewerActivity.this,InterviewerPublishActivity.class));
                break;
        }
    }


    private class MyAdapter extends FragmentPagerAdapter {

        private MyAdapter(@NonNull FragmentManager fm) {
            super(fm);
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return new HomeInterviewerFragment();
                case 1:
                    return new ChatInterviewerFragment();
                case 2:
                    return new PostInterviewerFragment();
                case 3:
                    return new MyInterviewerFramgent();
                default:
                    return null;
            }
        }

        @Override
        public int getCount() {
            return 4;
        }
    }
}
